<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>

                <!-- /section:settings.box -->
                <div class="row">
                    <form class="form-inline" action="<?php echo site_url(X_URL . 'article/index') ?>" method="get"
                          id="form2">
                        <?php echo csrf_hidden(); ?>
                        <label class="inline">产品标题:<input type="text" name="article_title" id="article_title"
                                                          value="<?php if (isset($search['keyword'])) {
                                                              echo $search['keyword'];
                                                          } ?>"/></label>
                        <button type="submit" class="btn btn-purple btn-sm" id="submit">
                            <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                            查询
                        </button>
                        <span class="btn btn-purple btn-sm" id="addarticle">
                            <span class="ace-icon fa fa-user icon-on-right bigger-110"></span>
                            新增产品
                        </span>
                    </form>

                    <div class="col-xs-12">
                    </div>
                    <table class="table table-striped table-bordered">
                        <thead>
                        <tr>
                            <th width="15%" class="center">发布时间</th>
                            <th class="center">所属分类</th>
                            <th class="center">标题</th>
                            <th class="center">操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php if ($articles) {
                            foreach ($articles as $key => $val) { ?>
                                <tr>
                                    <td class="center"><?php echo $val['create_time']; ?></td>
                                    <td class="center"><?php echo $val['category']; ?></td>
                                    <td class="center"><?php echo $val['title']; ?></td>

                                    <td class="center">
                                        <a href="<?php echo site_url(X_URL . 'article/edit/' . $val['id']); ?>">修改</a>&nbsp;
                                        <a class="red del" href="javascript:;"
                                           val="<?php echo site_url(X_URL . 'article/del/' . $val['id']); ?>"
                                           title="删除">删除</a>
                                    </td>
                                </tr>
                            <?php } ?>
                        <?php } ?>
                        </tbody>
                    </table>
                    <?php if ($pagination) { ?>
                        <ul class="pagination"><?php echo $pagination; ?></ul><?php } ?>
                    <!--                        {$page}-->
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->

</div><?php $this->load->view('common/footer'); ?>


<?php $this->load->view('common/footerjs'); ?>
<!-- inline scripts related to this page -->
<script type="text/javascript">

    $(function () {
        $("#officialnews ul").html('<div class="ace-icon fa fa-spinner fa-spin orange"></div>');
    })
    $("#addarticle").click(function () {
        window.location.href = "add";
    });
    $(".del").click(function () {
        var url = $(this).attr('val');
        bootbox.confirm({
            title: "系统提示",
            message: "确定要删除?",
            callback: function (result) {
                if (result) {
                    window.location.href = url;
                }
            },
            buttons: {
                "cancel": {"label": "取消"},
                "confirm": {
                    "label": "确定",
                    "className": "btn-danger"
                }
            }
        });
    });
    $("#submit").click(function () {
        var title = $("#title").val();
        if (title == '') {
            bootbox.dialog({
                title: "系统提示",
                message: "搜索标题必须填写！",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return false;
        }
        $("#form2").submit();
    });
    $(".beer_push").click(function () {
        var url = baseurl + "index.php/manage/article/push_baidu_beer";
        var aid = $(this).attr("val");
        $.ajax({
            url: url,
            type: "get",
            data: {'aid': aid},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.status == '1') {
                    bootbox.dialog({
                        title: "系统提示",
                        message: "推送成功，今日剩余推送" + data.remain + "条",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-success"
                            }
                        }
                    });
                    return false;
                } else {
                    bootbox.dialog({
                        title: "系统提示",
                        message: "推送失败，今日剩余推送" + data.remain + "条",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-danger"
                            }
                        }
                    });
                    return false;
                }
            }
        });
    });
</script>
</body>
</html>
